#include "../Basics/BasicStruct.cpp"

// 删除链表最大元素
int FindMax(List list) {
    ListNode* p = list;
    int max = p->data;
    while(p != NULL) {
        if (p->data > max) {
            max= p->data;
        }
        p = p->next;
    }
    return max;
}

List DeleteMax(List list) {
    ListNode* head = (ListNode*) malloc(sizeof(ListNode));
    head->next = list;
    ListNode* pre = head;
    ListNode* p = list;
    int max = FindMax(list);
    while(p != NULL) {
        if (p->data == max) {
            pre->next = p->next;
            free(p);
            p = pre->next;
            continue;
        }
        pre = p;
        p = p->next;
    }
    return head->next;
}

int main() {
    List list = CreateList();
    DeleteMax(list);
}